package com.bdzt.beidoubox.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.bdzt.beidoubox.R;
import com.bdzt.beidoubox.adapter.BoxListAdapter;
import com.bdzt.beidoubox.entity.BoxInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * 队友盒子列表
 */
public class TeamBoxListActivity extends BaseActivity {
    private ListView lv_teamList;
    private List<BoxInfo> list;
    private BoxListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_team_list);
        initView();
        initData();
    }

    private void initData() {
        for (int i = 0; i < 10; i++) {
            BoxInfo info = new BoxInfo();
            info.setBoxID("10086" + i);
            info.setBoxName("Box" + i);
            list.add(info);
        }
        adapter.notifyDataSetChanged();
    }

    private void initView() {
        list = new ArrayList<>();
        adapter = new BoxListAdapter(list, TeamBoxListActivity.this);

        lv_teamList = (ListView) findViewById(R.id.lv_teamList);
        lv_teamList.setAdapter(adapter);
        findViewById(R.id.tv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                TeamBoxListActivity.this.finish();
            }
        });
        lv_teamList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                BoxInfo info = list.get(position);
                Intent intent = new Intent(TeamBoxListActivity.this, AddBoxActivity.class);
                intent.putExtra("info", info);
                startActivityForResult(intent, 1);

            }
        });
    }


    public void add(View view) {
        startActivityForResult(new Intent(TeamBoxListActivity.this, AddBoxActivity.class), 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 0) {
        } else if (requestCode == 1) {
        }

    }
}
